home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol04 / 02a / basic / wordwrap.bas (.txt) < prev   
Microsoft Word for DOS Document  |  1988-09-22  |  2KB  |  41 lines

  1. D:\WORD4\NORMAL.STY
  2. HPLASER1
  3. '********* WordWrap.Bas - prints long strings with word wrap
  4. 'Copyright (c) 1988 Ethan Winer
  5. DEFINT A-Z
  6. DECLARE SUB WordWrap (X$, Wide)
  7. A$ = "This is the theme to Garry's show, the theme to Garry's show.  "
  8. B$ = "Garry called me up and asked if I would write his theme song.  "
  9. C$ = "I'm almost halfway finished, how do you like it so far.  "
  10. D$ = "How do you like the theme to Garry's show?  "
  11. E$ = "This is the theme to Garry's show, the theme to Garry's show.  "
  12. F$ = "This is the music that you hear as you watch the credits.  "
  13. G$ = "We're almost to the part where I start to whistle.  "
  14. H$ = "Then we'll watch It's Garry Shandling's show. "
  15. W$ = A$ + B$ + C$ + D$ + E$ + F$ + G$ + H$
  16. PRINT W$
  17. PRINT
  18. Wide = 60               'the maximum width of the display
  19. WordWrap W$, Wide
  20. SUB WordWrap (X$, Wide%)
  21.     Length% = LEN(X$)           'remember the length
  22.     Pointer% = 1                'start at the beginning of the string
  23.     'scan a block of eighty characters backwards, looking for a blank
  24.     'stop at the first blank, or if we reached the end of the string
  25.     DO
  26.        FOR X% = Pointer% + Wide% TO Pointer% STEP -1
  27.            IF MID$(X$, X%, 1) = " " OR X% = Length% + 1 THEN
  28.               'LOCATE , LeftMargin      'optional to tab in the left edge
  29.               PRINT MID$(X$, Pointer%, X% - Pointer%);
  30.               'LPRINT [TAB(LeftMargin)]; MID$(X$, Pointer%, X% - Pointer%)
  31.               Pointer% = X% + 1
  32.               WHILE MID$(X$, Pointer%, 1) = " "
  33.                  Pointer% = Pointer% + 1 'swallow extra blanks to next word
  34.               WEND
  35.               IF POS(0) > 1 THEN PRINT  'if cursor didn't wrap next line
  36.               EXIT FOR                  'done with this block
  37.            END IF
  38.        NEXT
  39.     LOOP WHILE Pointer% < Length%       'loop until done
  40. END SUB
  41.